package com.cmccgz.udacs_landlord_webapp.main.test;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.cmccgz.baselibrary.base.BaseActivity;
import com.cmccgz.udacs_landlord_webapp.R;
import com.cmccgz.udacs_landlord_webapp.base.AppConfig;
import com.cmccgz.udacs_landlord_webapp.main.user.login.LoginActivity;
import com.cmccgz.udacs_landlord_webapp.utils.ViewHelper;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/7/5 10:02
 */

public class SelectUrlActivity extends BaseActivity {

    private RadioGroup radioGroup;
    public static final String BaseUrl_75 = "http://udacs-dev.gmcciot.com:8010";
    public static final String BaseUrl_76 = "http://udacs-staging.gmcciot.com:8010";
    public static final String BaseUrl_Test = "http://udacs-test.gmcciot.com:8010";
    public static final String BaseUrl_Shengchan = "https://udacs.gmcciot.com:9527";


    @Override
    protected int setLayoutId() {
        return R.layout.activity_select_url;
    }

    @Override
    protected void initView() {
        ViewHelper helper = ViewHelper.instance(this);
        if (helper != null) {
            helper.setTitle("请选择环境");
            helper.setAllVisable(false);
        }
        radioGroup = (RadioGroup) findViewById(R.id.rg_sel);
        RadioButton rb_75 = (RadioButton) findViewById(R.id.rb_75);
        RadioButton rb_76 = (RadioButton) findViewById(R.id.rb_76);
        RadioButton rb_test = (RadioButton) findViewById(R.id.rb_test);
        RadioButton rb_shengchan = (RadioButton) findViewById(R.id.rb_shengchan);
        rb_75.setText("http://udacs-dev.gmcciot.com:8010(开发环境)");
        rb_76.setText("http://udacs-staging.gmcciot.com:8010(演示环境)");
        rb_test.setText("http://udacs-test.gmcciot.com:8010(测试环境)");
        rb_shengchan.setText("https://udacs.gmcciot.com:9527(生产环境)");


        String baseUrl = AppConfig.getBaseUrl();
        if (TextUtils.isEmpty(baseUrl)) {
            rb_75.setChecked(true);
        } else if (BaseUrl_75.equals(baseUrl)) {
            rb_75.setChecked(true);
        } else if (BaseUrl_76.equals(baseUrl)) {
            rb_76.setChecked(true);
        } else if (BaseUrl_Test.equals(baseUrl)) {
            rb_test.setChecked(true);
        } else if (BaseUrl_Shengchan.equals(baseUrl)) {
            rb_shengchan.setChecked(true);
        } else {
            rb_75.setChecked(true);
            AppConfig.setBaseIp( "");
        }

        Button button = (Button) findViewById(R.id.btn_save);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
                switch (checkedRadioButtonId) {
                    case R.id.rb_75:
                        AppConfig.setBaseIp(BaseUrl_75);
                        break;
                    case R.id.rb_76:
                        AppConfig.setBaseIp(BaseUrl_76);
                        break;
                    case R.id.rb_test:
                        AppConfig.setBaseIp(BaseUrl_Test);
                        break;
                    case R.id.rb_shengchan:
                        AppConfig.setBaseIp(BaseUrl_Shengchan);
                        break;
                    default:
                        break;
                }
                Intent intent = new Intent(mContext, LoginActivity.class);
                mContext.startActivity(intent);
                finish();
            }
        });
    }

    @Override
    protected void initFragment() {

    }

    @Override
    protected void beforePermission() {

    }

    @Override
    protected int setSystemBarColorId() {
        return 0;
    }
}
